<?php
defined('BASEPATH') OR exit('No direct script access allowed');
 
class Moment extends CI_Controller {

	 var $dbmain;

     function __construct()
	 {
		    parent::__construct();
            include_once "func.php";
            $this->dbmain = $db;
	 }

	public function getlist(){

		$pageno = 1;
		if(isset($_GET['page_no'])){
			$pageno = $_GET['page_no'];
		}
		$pagesize = 10 ;
  	 	$rs_number = ($pageno - 1) * $pagesize ;


		$sql = "select a.*,b.nickname,b.thumb,b.height,b.sex from moment a,member b where a.member_id=b.id order by a.id desc limit $rs_number,$pagesize";
		$momentList = $this->dbmain->get_results($sql);
		$count = count($momentList);
 
        $data = array(
			'moment_list' => $momentList,
			'count' => $count,
			'page_no' => $pageno
		);
  
		ajax_return($data);
	}



	public function detail(){

		if(!isset($_GET["id"])){
			exit;
		}

	 	$momentid = $_GET["id"];
	 	$sql = "select a.*,b.thumb,b.height,b.sex from moment a,member b where a.member_id=b.id and a.id='$momentid'";
 	 	$moment = $this->dbmain->get_row($sql);

  	 	$sql = "select a.*,b.nickname,b.thumb from moment_reply a,member b where a.member_id=b.id and a.moment_id='$momentid'";
		$replys = $this->dbmain->get_results($sql);

        $data = array(		
			'moment' => $moment,
			'replys' => $replys
		);
  
		ajax_return($data);
	}



	public function index()
	{  
  
 	}

}
